package com.redstars.generate.controller;

import com.redstars.generate.page.PageResult;
import com.redstars.generate.result.Result;
import com.redstars.generate.vo.SysFieldTypeVo;
import lombok.AllArgsConstructor;
import com.redstars.generate.service.SysFieldTypeService;
import com.redstars.generate.query.SysFieldTypeQuery;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
import java.util.Set;

/**
* 字段类型管理
*
* @author zhouhx 
* @since 1.0.0 2022-10-05
*/
@RestController
@RequestMapping("gen/fieldtype")
@AllArgsConstructor
public class SysFieldTypeController {
    private final SysFieldTypeService sysFieldTypeService;

    /* *
     *
     * @author zhuohx
     * @description 分页
     * @parms  [query]
     * @return com.redstars.generate.result.Result<com.redstars.generate.page.PageResult<com.redstars.generate.vo.SysFieldTypeVo>>
     * @throws
     * @date 2022/10/5 15:50
     */
    @GetMapping("page")
    public Result<PageResult<SysFieldTypeVo>> page(@Valid SysFieldTypeQuery query){
        PageResult<SysFieldTypeVo> page = sysFieldTypeService.page(query);

        return Result.ok(page);
    }

    /* *
     *
     * @author zhuohx
     * @description 详情
     * @parms  [query]
     * @return com.redstars.generate.result.Result<com.redstars.generate.vo.SysFieldTypeVo>
     * @throws
     * @date 2022/10/5 15:50
     */
    @GetMapping("{id}")
    public Result<SysFieldTypeVo> detail(@PathVariable("id") Long id){
        SysFieldTypeVo detail = sysFieldTypeService.detail(id);

        return Result.ok(detail);
    }

    /* *
     *
     * @author zhuohx
     * @description 获取全部字段类型
     * @return com.redstars.generate.result.Result<java.util.Set<java.lang.String>>
     * @throws
     * @date 2022/10/6 8:33
     */
    @GetMapping("list")
    public Result<Set<String>> list() {
        Set<String> set = sysFieldTypeService.getTypeList();

        return Result.ok(set);
    }
    /* *
     *
     * @author zhuohx
     * @description 保存
     * @parms  [vo]
     * @return com.redstars.generate.result.Result<java.lang.String>
     * @throws
     * @date 2022/10/5 15:51
     */
    @PostMapping
    public Result<String> save(@RequestBody SysFieldTypeVo vo){
        sysFieldTypeService.save(vo);

        return Result.ok();
    }

    /* *
     *
     * @author zhuohx
     * @description 修改
     * @parms  [vo]
     * @return com.redstars.generate.result.Result<java.lang.String>
     * @throws
     * @date 2022/10/5 15:51
     */
    @PutMapping
    public Result<String> update(@RequestBody @Valid SysFieldTypeVo vo){
        sysFieldTypeService.update(vo);

        return Result.ok();
    }

    /* *
     *
     * @author zhuohx
     * @description 删除
     * @parms  [idList]
     * @return com.redstars.generate.result.Result<java.lang.String>
     * @throws
     * @date 2022/10/5 15:51
     */
    @DeleteMapping
    public Result<String> delete(@RequestBody List<Long> idList){
        sysFieldTypeService.delete(idList);

        return Result.ok();
    }
}